{extends 'admin/layout/main.tpl'}

{block title}编辑用户{/block}
{block smallTitle}创建或编辑用户。{/block}

{block breadcrumb}
<li>用户管理</li>
<li><a href="{route('AdminMemberList')}">用户列表</a></li>
<li><a href="{route('AdminMemberEdit',['id'=>$data.id])}">用户信息</a></li>
{/block}

{block main}
<div class="row">
	<div class="col-lg-12">
		<section class="panel">
			<header class="panel-heading">用户信息</header>
			<div class="panel-body">
				<form method="post" class="form-horizontal tasi-form" action="">
				{if $data}
					<div class="form-group">
						<label class="col-lg-2 col-sm-2 control-label">#</label>
						<div class="col-lg-10">
							<p class="form-control-static">{$data.id}</p>
						</div>
					</div>
				{/if}
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">昵称</label>
                        <div class="col-sm-10">
                            {$data.nickname|escape}
                            {*<input type="text" class="form-control" name="nickname" value="{Input::old('nickname')|default:$data.nickname|escape}">*}
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">电话</label>
                        <div class="col-sm-10">
                            {$data.mobile|escape}
                            {*<input type="text" class="form-control" name="mobile" value="{Input::old('mobile')|default:$data.mobile|escape}">*}
                        </div>
                    </div>

                    {*<div class="form-group">*}
                        {*<label class="col-sm-2 col-sm-2 control-label">积分</label>*}
                        {*<div class="col-sm-10">*}
                            {*<input type="text" class="form-control" name="integral" value="{Input::old('integral')|default:$data.integral|escape}">*}
                        {*</div>*}
                    {*</div>*}

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">头像</label>
                        <div class="col-sm-10">
                            {if $data.avatar_id}<img
                                src="{route('FilePull', ['id'=>$data.avatar_id])}">{else}<img
                                    src="http://www.placehold.it/150x150/EFEFEF/AAAAAA&amp;text=no+image"
                                    alt="" />{/if}
                        </div>
                    </div>

                    {*<div class="form-group">*}
                        {*<label class="col-sm-2 col-sm-2 control-label">签名</label>*}
                        {*<div class="col-sm-10">*}
                            {*<textarea name="signature" class="form-control">{Input::old('signature')|default:$data.signature|escape}</textarea>*}
                        {*</div>*}
                    {*</div>*}

                    {*<div class="form-group">*}
                        {*<label class="col-sm-2 col-sm-2 control-label">性别</label>*}
                        {*<div class="col-sm-10">*}
                            {*<select class="form-control m-b-10" name="status">*}
                                {*{foreach $sex as $key=>$item}*}
                                    {*<option value="{$key}" {if $data.sex==$key}selected="selected"{/if}>{$item}</option>*}
                                {*{/foreach}*}
                            {*</select>*}
                        {*</div>*}
                    {*</div>*}

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">状态</label>
                        <div class="col-sm-10">
                            {$status[$data.status]}
                            {*<select class="form-control m-b-10" name="status">*}
                                {*{foreach $status as $key=>$item}*}
                                {*<option value="{$key}" {if $data.status==$key}selected="selected"{/if}>{$item}</option>*}
                                {*{/foreach}*}
                            {*</select>*}
                        </div>
                    </div>


					<div class="form-group">
						<div class="col-lg-offset-2 col-lg-10" id="data_sub">
							<input type="hidden" name="id" value="{$data.id}">
                            <input type="hidden" name="mod_flag" value="{$data.mod_flag}">
							{*<button class="btn btn-primary" type="submit">保存</button>*}
						</div>
					</div>
				</form>
			</div>
		</section>
	</div>
</div>
{/block}
{block script}
    <link href="{asset('admin/css/bootstrap-fileupload.min.css')}" rel="stylesheet" type="text/css" />
    <script src="{asset('admin/js/bootstrap-fileupload.min.js')}" type="text/javascript" ></script>
    <script>

        // 文件上传。
        $.fn.eduFileUpload = function(options){
            options = $.extend({
                name : null
            }, options || {});
            function formatSize(size) {
                var unit = ['B', 'KB', 'MB', 'GB', 'TB', 'DB'];
                var i = arguments[1];
                if (typeof arguments[1] == 'undefined') {
                    i = 0;
                }
                if (size < 1024) {
                    return size.toFixed(2)+unit[i];
                } else {
                    return formatSize(size/1024, ++i);
                }
            }
            this.each(function() {
                var $this = $(this);
                var xhr_before = null;

                var $statistics = $('<span class="statistics" style="display: none;">\
                <span class="loaded">0M</span> /\
                <span class="file_size">0M</span>\
                <span class="upload_progress">0%</span>\
            </span>').appendTo($this);

                var $file = $this.find(':file:first');
                var $input = options.name ? $this.find('input[type="hidden"][name="' + options.name + '"]') : $this.find('input[type="hidden"]:first');

                $this.find('.close').on('click', function(){
                    $file.val('');
                    $input.val('');
                    if (xhr_before){
                        xhr_before.abort();
                        xhr_before = null;
                    }
                    $this.data('uploading', false);
                });

                $this.data('uploading', false);
                $file.on('change', function(){
                    if( ! this.files[0]) return;
                    $this.data('uploading', true);
                    var data = new FormData();
                    data.append('body', this.files[0]);
                    $.ajax({
                        type        : 'POST',
                        url         : '{route('FileUpload')}',
                        data        : data,
                        processData : false,
                        contentType : false,
                        beforeSend  : function(xhr){
                            if (xhr_before) xhr_before.abort();
                            xhr_before = xhr;
                            xhr.progress = function(e) {
                                if (e.lengthComputable) {
                                    var percentComplete = Math.round(e.loaded * 100 / e.total);
                                    $statistics.find('.upload_progress').html(percentComplete+'%');
                                    $statistics.find('.loaded').html(formatSize(e.loaded));
                                } else {
                                    $statistics.find('.loaded').html('上传中');
                                    $statistics.find('.upload_progress').html('');
                                }
                            };
                        },
                        success     : function(json){
                            xhr_before = null;
                            $this.data('uploading', false);
                            if(json.mime.substring(0,6) == 'image/'){
                                $input.val(json.file_id);
                            }else{
                                $input.val('');
                                $this.find('.close').trigger('click');
                                ialert('不支持的图片格式。');
                            }
                        },
                        error       : function (xhr) {
                            var message = xhr.responseText;
                            xhr_before = null;
                            $this.data('uploading', false);
                            $this.find('.close').trigger('click');
                        }
                    });
                });
            });
        };

        $('#upload_picture').eduFileUpload({ name : 'avatar_id' });

    </script>
{/block}